<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>达内－NetCTOSS</title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
        <script language="javascript" type="text/javascript" src="../js/jquery-1.4.3.js"></script>
        <script language="javascript" type="text/javascript">
        	var realName=true,rPhone=true,rEmail=true;
            //保存成功的提示消息
            function showResult() {
            	if(realName == true){
            		var flag1 = 0;
		            var checkobj=document.getElementById("CheckBoxList");
		            var checks = checkobj.getElementsByTagName("input");
		            for(var n = 0; n<checks.length;n++){
		            	if( checks[n].checked==true){
		            		flag1=1;
		            	}
		            }
		            if(flag1==0){
		            	$("#save_result_info").text("请至少选择一项权限");
		                showResultDiv(true);
		                window.setTimeout("showResultDiv(false);", 1000);
		            	return;
		            }
                	showResultDiv(true);
                	document.forms[0].submit();
                	window.setTimeout("showResultDiv(false);", 1000);
            	}
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
             $(function(){
	            //姓名
	            $("#realName").blur(function(){
	            	var name = $(this).val();
	            	var reg = /^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$/;
	            	if(!reg.test(name)){
	            		$("#realNameMsg").addClass("error_msg").text("请输入正确的姓名");
	            		realName = false;
	            		return;
	            	}else{
	            		$("#realNameMsg").removeClass("error_msg").text("输入正确");
	            		realName = true;
	            	}
	            });
	            //电话
           		$("#thePhone").blur(function(){
            		var phone = $(this).val();
            		var tel = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
            		var pho = /\d{3}-\d{8}|\d{4}-\d{7}/;
            		if(!tel.test(phone)&&!pho.test(phone)){
            			$("#thePhoneMsg").addClass("error_msg").text("请输入正确的号码");
            			rPhone=false;
            			return;
            		}else{
            			$("#thePhoneMsg").removeClass("error_msg").text("输入正确");
            			rPhone=true;
            		}
            	});
            	//Email
            	$("#theEmail").blur(function(){
            		var email = $(this).val();
            		var len = email.length;
            		var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            		if(!reg.test(email)||len>50){
            			if(email==(null||"")){
            				$("#theEmailMsg").removeClass("error_msg").text("50长度以内，合法的Email格式");
            				rEmail=true;
            				return;
            			}
            			$("#theEmailMsg").addClass("error_msg").text("请输入正确的Email地址");
            			rEmail=false;
            			return;
            		}else{
            			$("#theEmailMsg").removeClass("error_msg").text("输入正确");
            			rEmail=true;
            		}
            	});
            });
        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="#">[退出]</a>            
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <ul id="menu">
                <li><a href="../index/index" class="index_off"></a></li>
                <li><a href="../role/findRole" class="role_off"></a></li>
                <li><a href="../admin/findAdmin" class="admin_on"></a></li>
                <li><a href="../cost/findCost" class="fee_off"></a></li>
                <li><a href="../account/findAccount" class="account_off"></a></li>
                <li><a href="../service/findService" class="service_off"></a></li>
                <li><a href="../bill/findBill" class="bill_off"></a></li>
                <li><a href="../report/findReport" class="report_off"></a></li>
                <li><a href="../user/userInfo" class="information_off"></a></li>
                <li><a href="../user/userModiPwd" class="password_off"></a></li>
            </ul>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">            
            <div id="save_result_info" class="save_success">保存成功！</div>
            <form action="saveAdmin" method="post" class="main_form">
            		<input type="hidden" name="admin.id" value="<s:property value="id"/>"/>
                    <div class="text_info clearfix"><span>姓名：</span></div>
                    <div class="input_info">
                    	<s:textfield name="admin.name" id="realName"></s:textfield>
                        <span class="required">*</span>
                        <div class="validate_msg_long" id="realNameMsg">20长度以内的汉字、字母、数字的组合</div>
                    </div>
                    <div class="text_info clearfix"><span>管理员账号：</span></div>
                    <div class="input_info">
                    	<s:textfield readonly="true" cssClass="readonly" name="admin.adminCode"></s:textfield>
                    </div>
                    <div class="text_info clearfix"><span>电话：</span></div>
                    <div class="input_info">
                        <s:textfield name="admin.telephone" id="thePhone"></s:textfield>
                        <span class="required">*</span>
                        <div class="validate_msg_long" id="thePhoneMsg">正确的电话号码格式：手机或固话</div>
                    </div>
                    <div class="text_info clearfix"><span>Email：</span></div>
                    <div class="input_info">
                        <s:textfield cssClass="width200" name="admin.email" id="theEmail"></s:textfield>
                        <span class="required">*</span>
                        <div class="validate_msg_medium" id="theEmailMsg">50长度以内，正确的 email 格式</div>
                    </div>
                    <div class="text_info clearfix"><span>角色：</span></div>
                    <div class="input_info_high">
                        <div class="input_info_scroll" id="CheckBoxList">
                        	<s:checkboxlist list="roles" name="admin.roleIds" listKey="id" listValue="name"></s:checkboxlist>
                        </div>
                        <span class="required">*</span>
                        <div class="validate_msg_tiny">至少选择一个</div>
                    </div>
                    <div class="button_info clearfix">
                        <input type="button" value="保存" class="btn_save" onclick="showResult();" />
                        <input type="button" value="取消" class="btn_save" onclick="javascript:history.go(-1);"/>
                    </div>
                </form>  
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)加拿大达内IT培训集团公司 </span>
        </div>
    </body>
</html>
